package mogowtools.client.fx;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.JavaScriptObject;

public class Properties {
	
	private class Property
	{
		private String cssProperty;
		private String beginValue = null;
		private String endValue;
		
		Property(String cssProp, String beginVal, String endVal)
		{
			this.cssProperty = cssProp;
			this.beginValue = beginVal;
			this.endValue = endVal;
		}
		
		Property(String cssProp, String endVal)
		{
			this.cssProperty = cssProp;
			this.endValue = endVal;
			this.beginValue = null;
		}
		
		public String toString()
		{
			return "'"+this.cssProperty+"':"+(beginValue == null ? endValue : "["+beginValue+", "+endValue+"]");
		}
		
		public String getNomProperty()
		{
			return this.cssProperty;
		}
		
		public String getBeginValue()
		{
			return this.beginValue;
		}
		
		public String getEndValue()
		{
			return this.endValue;
		}
		
	}
	
	private List properties = new ArrayList();
	
	public Properties()
	{
		
	}
	
	public void addProperty(String cssProp, String beginVal, String endVal)
	{
		this.properties.add(new Property(cssProp, beginVal, endVal));
	}
	
	public void addProperty(String cssProp, String endVal)
	{
		this.properties.add(new Property(cssProp, endVal));
	}
	
	private int nbProperties()
	{
		return properties.size();
	}
	
	private Property getProperty(int n)
	{
		return (Property)properties.get(n);
	}
	
	public native JavaScriptObject properties()
	/*-{
		var j = new Object();
		var nbProp = this.@mogowtools.client.fx.Properties::nbProperties()();
		for (var i = 0; i < nbProp; i++)
		{
			var p = this.@mogowtools.client.fx.Properties::getProperty(I)(i);
			var prop = p.@mogowtools.client.fx.Properties.Property::getNomProperty()();
			var beginval = p.@mogowtools.client.fx.Properties.Property::getBeginValue()();
			var endval = p.@mogowtools.client.fx.Properties.Property::getEndValue()();
			if (beginval == null)
				j[prop] = endval;
			else
				j[prop] = [beginval, endval];
		}
		return j;
	}-*/;
}
